home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / Utilities / CalibrateLuminance / GetALuminance.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-23  |  3.0 KB  |  98 lines  |  [TEXT/KAHL]

  1. /*
  2. GetALuminance.c
  3. © 1990-1992 Denis G. Pelli
  4. Two subroutines used by CalibrateLuminance.c. Probably not useful outside that context.
  5.  
  6. HISTORY:
  7. 7/28/90    dgp    wrote it.
  8. 9/24/90    dgp    changed nBackground to VBackground.
  9. 6/25/91 dgp fixed bug pointed out by Sujeet Paul whereby LToVHunt() made a superfluous
  10. call to GetALuminance() with frames=1, forcing use of the A/D even if it wasn't available.
  11. On a machine without an A/D card this would cause CalibrateLuminance to fail.
  12. On machines with an A/D card this wasted a second on each call to LToVHunt().
  13. 8/24/91    dgp    Made compatible with THINK C 5.0.
  14. 12/17/92 dgp Enhanced to support arbitrary dacSize. Replaced 256 by LP->VMax+1 
  15. in LToVHunt.
  16. 12/21/92 dgp No longer load unused dac bits.
  17. */
  18. #include "VideoToolbox.h"
  19. #include "Luminance.h"
  20.  
  21. double GetALuminance(luminanceRecord *LP,GDHandle device,
  22.     int frames,double LuminancePerVoltage,int entry,int red,int green,int blue);
  23. void LToVHunt(luminanceRecord *LP,GDHandle device,CWindowPtr window,
  24.     double LuminancePerVoltage,int frames,double darkLuminance);
  25.  
  26.  
  27. double GetALuminance(luminanceRecord *LP,GDHandle device,
  28.     int frames,double LuminancePerVoltage,int entry,int red,int green,int blue)
  29. /*
  30. Get luminance produced by an RGB triplet. If frames==0 then ask for manual
  31. reading. If frames!=0 then use A/D to make automatic reading.
  32. */
  33. {
  34.     static double L;
  35.     static char string[100];
  36.     long finalTicks;
  37.     short left;
  38.  
  39.     left=LP->leftShift;
  40.     LP->table[entry].rgb.red   = red<<left;
  41.     LP->table[entry].rgb.green = green<<left;
  42.     LP->table[entry].rgb.blue  = blue<<left;
  43.     LoadLuminances(device,LP,entry,entry);        /* load clut entry */
  44.     if(frames){
  45.         Delay(60L,&finalTicks);                        /* wait for photometer to settle */
  46.         LoadLuminances(device,LP,entry,entry);    /* synchronize to display */
  47.         L=VoltsDuringFrame(frames)*LuminancePerVoltage;
  48.     }
  49.     else{
  50.         printf("Please enter luminance in %s (%4.1f):",LP->units,L);
  51.         gets(string);
  52.         sscanf((char *)string,"%lf",&L);
  53.     }
  54.     return L;
  55. }
  56.  
  57.  
  58. void LToVHunt(luminanceRecord *LP,GDHandle device,CWindowPtr window,
  59.     double LuminancePerVoltage,int frames,double darkLuminance)
  60. /*
  61. finds the DAC setting j, such that the desired luminance is
  62. between Lj and Lj+1. This is achieved by actually measuring
  63. the resulting luminances, before the LuminanceRecord is
  64. fully defined. The search proceeds by bisection:
  65. LP->LBackground==desired luminance;
  66. LP->VBackground==j;
  67. */
  68. {
  69.     int ju,jm,jl;
  70.     double LMeasured;
  71.     WindowPtr oldWindow;
  72.     int index=1;
  73.  
  74.     GetPort(&oldWindow);
  75.     SetPort((WindowPtr)window);
  76.     BringToFront((WindowPtr)window);
  77.     PmBackColor(index);
  78.     EraseRect(&window->portRect);
  79.     jl=0;
  80.     ju=LP->VMax+1;
  81.     while (ju-jl > 1) {
  82.         jm=(ju+jl)/2;
  83.         LMeasured=GetALuminance(LP,device,frames,LuminancePerVoltage
  84.             ,index,jm,jm,jm);
  85.         LMeasured-=darkLuminance;
  86.         if (LP->LBackground > LMeasured)
  87.             jl=jm;
  88.         else
  89.             ju=jm;
  90.     }
  91.     LP->VBackground=jl;
  92.     LP->table[index].rgb=(**(**(**device).gdPMap).pmTable).ctTable[index].rgb;
  93.     LoadLuminances(device,LP,index,index);        /* restore clut entry */
  94.     SendBehind((WindowPtr)window,NULL);
  95.     SetPort(oldWindow);
  96.     return;
  97. }
  98.